package com.ht.shortlink.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ht.shortlink.project.common.convention.result.Result;
import com.ht.shortlink.project.common.convention.result.Results;
import com.ht.shortlink.project.dto.req.ShortLinkRecyclePageReqDTO;
import com.ht.shortlink.project.dto.req.ShortLinkRecycleRecoverReqDTO;
import com.ht.shortlink.project.dto.req.ShortLinkRecycleRemoveReqDTO;
import com.ht.shortlink.project.dto.req.ShortLinkRecycleSaveReqDTO;
import com.ht.shortlink.project.dto.resp.ShortLinkPageRespDTO;
import com.ht.shortlink.project.service.IRecycleBinService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 *  回收站服务层
 */
@RestController
@RequiredArgsConstructor
public class RecycleBinController {

    private final IRecycleBinService recycleBinService;

    /**
     *  移至回收站
     */
    @PostMapping("/api/short-link/v1/recycle/save")
    public Result<Void> save2Bin(@RequestBody ShortLinkRecycleSaveReqDTO requestParam){
        recycleBinService.save2Bin(requestParam);
        return Results.success();
    }


    /**
     *  分页查询回收站短链接
     */
    @GetMapping("/api/short-link/v1/recycle/page")
    public Result<IPage<ShortLinkPageRespDTO>> queryPage(ShortLinkRecyclePageReqDTO requestParam){
        return Results.success(recycleBinService.queryPage(requestParam));
    }

    /**
     *  恢复短链接
     */
    @PostMapping("/api/short-link/v1/recycle/recover")
    public Result<Void> recycleRecover(@RequestBody ShortLinkRecycleRecoverReqDTO requestParam){
        recycleBinService.recycleRecover(requestParam);
        return Results.success();
    }

    /**
     *  删除短链接
     */
    @PostMapping("/api/short-link/v1/recycle/remove")
    public Result<Void> recycleRemove(@RequestBody ShortLinkRecycleRemoveReqDTO requestParam){
        recycleBinService.recycleRemove(requestParam);
        return Results.success();
    }
}
